﻿@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}
<div class="poppan">
    <table>
        <tr>
            <td>宝宝姓名*</td>
            <td><input type="text" name="_custName" autocomplete="off" class="layui-input" value="@ViewBag.data["custName"]"></td>
            <td>联系电话*</td>
            <td><input type="text" name="_custTel" autocomplete="off" class="layui-input" value="@ViewBag.data["custTel"]"></td>
        </tr>
        <tr>
            <td>出生日期</td>
            <td><input type="text" name="_birdDate" id="_birdDate" autocomplete="off" class="layui-input date" value="@ViewBag.data["birdDate"]"></td>
            <td>出生日期已确认</td>
            <td><input type="checkbox" name="_birDateState" lay-skin="switch" @(ViewBag.data["birDateState"].ToString() == "1" ? "checked" : "")></td>
        </tr>
        <tr>
            <td>宝宝小名</td>
            <td><input type="text" name="_childName" autocomplete="off" class="layui-input" value="@ViewBag.data["childName"]"></td>
            <td>性别</td>
            <td>
                <input type="radio" name="_sex" value="男" title="男" @(ViewBag.data["sex"].ToString() == "男" ? "checked" : "")>
                <input type="radio" name="_sex" value="女" title="女" @(ViewBag.data["sex"].ToString() == "女" ? "checked" : "")>
            </td>
        </tr>
        <tr>
            <td>家长姓名</td>
            <td><input type="text" name="_linkName" autocomplete="off" class="layui-input" value="@ViewBag.data["linkName"]"></td>
            <td>关系</td>
            <td>
                <select name="_linkRelation">
                    @foreach (var dr in ViewBag.dict["linkRelation"])
                    {
                        <option value="@dr.Key" @(dr.Key == ViewBag.data["linkRelation"].ToString() ? "selected" : "")>@dr.Value</option>
                    }
                </select>
            </td>
        </tr>
        <tr>
            <td>渠道来源</td>
            <td>
                <select name="_custFromId">
                    @foreach (var dr in ViewBag.dict["custFromId"])
                    {
                        <option value="@dr.Key" @(dr.Key == ViewBag.data["custFromId"].ToString() ? "selected" : "")>@dr.Value</option>
                    }
                </select>
            </td>
            <td>来源备注</td>
            <td>
                <input type="text" name="_custFromRemark" autocomplete="off" class="layui-input" value="@ViewBag.data["custFromRemark"]">
            </td>
        </tr>
        <tr>
            <td>微信号</td>
            <td><input type="text" name="_WeiXin" autocomplete="off" class="layui-input" value="@ViewBag.data["WeiXin"]"></td>
            <td>固定电话</td>
            <td><input type="text" name="_Gddh" autocomplete="off" class="layui-input" value="@ViewBag.data["Gddh"]"></td>
        </tr>
        <tr>
            <td>意向课程</td>
            <td><input type="text" name="_IntentionCourse" autocomplete="off" class="layui-input" value="@ViewBag.data["IntentionCourse"]"></td>
            <td>意向日期</td>
            <td><input type="text" name="_IntentionDate" id="_IntentionDate" autocomplete="off" class="layui-input date" value="@ViewBag.data["IntentionDate"]"></td>
        </tr>
        <tr>
            <td>重要程度</td>
            <td><input type="text" name="_Importance" autocomplete="off" class="layui-input" value="@ViewBag.data["Importance"]"></td>
            <td>客户等级</td>
            <td>
                <select name="_Cusgrade" lay-verify="required" disabled>
                    <option value=""></option>
                    @foreach (var dr in ViewBag.dict["Cusgrade"])
                    {
                        <option value="@dr.Key" @(dr.Key == ViewBag.data["Cusgrade"].ToString() ? "selected" : "")>@dr.Value</option>
                    }
                </select>
            </td>
        </tr>
        <tr>
            <td>地址</td>
            <td colspan="3">
                <input type="text" name="_Address" autocomplete="off" class="layui-input" value="@ViewBag.data["Address"]">
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td colspan="3">
                <textarea name="_custRemark" class="layui-textarea">@ViewBag.data["custRemark"]</textarea>
            </td>
        </tr>

    </table>
</div>

<div class="poppanDiv">
    <table class="layui-table" lay-filter="dgrid" id="dgrid">
        <thead>
            <tr>
                <th lay-data="{field:'id',type: 'checkbox'}"></th>
                <th lay-data="{field:'linkname',sort: true}">姓名 </th>
                <th lay-data="{field:'linkrelation',sort: true}">关系 </th>
                <th lay-data="{field:'linktel',sort: true}">电话</th>
                <th lay-data="{field:'iskids',sort: true}">是否二孩</th>
            </tr>
        </thead>
    </table>  
</div>

@section fooler{
    <script>
        layui.use(['element', 'table', 'layer', 'laypage', 'form', 'laydate'], function () {
            //监听头工具栏事件
            var table = layui.table;
            table.init("dgrid", {
                url: '../Customer/Contract/Data?id=@ViewBag.id&keyCode=@ViewBag.keyCode',
                id: 'dgrid',               
                cellMinWidth: 120,
                toolbar: 'default',
                defaultToolbar: []  
            });
            //监听单击
            table.on('rowDouble(dgrid)', function (obj) {
                var data = obj.data;
                var index = layui.layer.open({
                                type: 2,
                                content: '../Customer/Contract?id=' + data.id + '&keyCode=' + data.keycode+'&cid=@ViewBag.id&ckeyCode=@ViewBag.keyCode',
                                title: '编辑联系人',
                                area: ['360px', '450px'],
                                maxmin: true
                            });
            });
            table.on('toolbar(dgrid)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id),data = checkStatus.data; //获取选中的数据
                switch (obj.event) {
                    case 'add':
                        var index = layui.layer.open({
                            type: 2,                           
                            content: '../Customer/Contract?id=-1&cid=@ViewBag.id&ckeyCode=@ViewBag.keyCode',
                            title: '添加联系人',
                            area: ['360px','450px'],
                            maxmin: true
                        });
                        break;
                    case 'update':
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else if (data.length > 1) {
                            layer.msg('只能同时编辑一个');
                        } else {   
                            var data = checkStatus.data[0];
                            var index = layui.layer.open({
                                type: 2,
                                content: '../Customer/Contract?id=' + data.id + '&keyCode=' + data.keycode+'&cid=@ViewBag.id&ckeyCode=@ViewBag.keyCode',
                                title: '编辑联系人',
                                area: ['360px', '450px'],
                                maxmin: true
                            });
                        }
                        break;
                    case 'delete':
                        var Ids = "";
                        var KeyCodes = "";                        
                        if (checkStatus.data.length > 0) {
                            for (var i = 0; i < checkStatus.data.length; i++) {
                                var id = checkStatus.data[i].id;
                                Ids += "," + id;
                                KeyCodes += "," + checkStatus.data[i].keycode;
                            }
                            Ids = Ids.substring(1);
                            KeyCodes = KeyCodes.substring(1);
                        }
                        if (Ids == "") {
                            layui.layer.msg("你没有选择记录！");
                            return;
                        }                       
                        layer.confirm("您确定要删除吗？", function (index) {
                            layer.close(index);
                            $.ajax({
                                type: 'POST',
                                url: '../Main/Del?type=Contract',
                                data: {
                                    Ids: Ids,
                                    KeyCodes: KeyCodes,
                                    t: new Date().getTime()
                                },
                                dataType: "json",
                                success: function (data) {
                                    layui.layer.msg(data.message);
                                    if (data.code == "0000") {                                        
                                        layui.table.reload("dgrid");
                                        layer.msg('删除成功');
                                    }
                                }
                            });
                        });                       
                        break;
                };
            });          
        });

        //关闭
        function HideModal(id) {
            layui.layer.closeAll();
            layui.table.reload("dgrid");
        }
    </script>
}

